package com.ghoul.gateway.modular.vo;


import lombok.Data;

/**
 * rest 返回值
 *
 * @param <T>
 */
@Data
public class RestResponse<T> {
    // 返回状态【0-成功，1-业务失败，999-表示系统异常】
    private int statusCode;
    private String msg = "";
    private T data;

    /**
     * 成功返回data
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> RestResponse success(T data) {
        RestResponse responseVO = new RestResponse();
        responseVO.setStatusCode(0);
        responseVO.setData(data);

        return responseVO;
    }

    /**
     * 成功不返data
     * @return
     */
    public static RestResponse success() {
        RestResponse responseVO = new RestResponse();
        responseVO.setStatusCode(0);
        return responseVO;
    }

    /**
     * 业务失败
     *
     * @param msg
     * @return
     */
    public static RestResponse serviceFail(String msg) {
        RestResponse responseVO = new RestResponse();
        responseVO.setStatusCode(1);
        responseVO.setMsg(msg);

        return responseVO;
    }

    /**
     * 系统异常
     *
     * @param msg
     * @return
     */
    public static RestResponse appFail(String msg) {
        RestResponse responseVO = new RestResponse();
        responseVO.setStatusCode(999);
        responseVO.setMsg(msg);

        return responseVO;
    }

}
